<!DOCTYPE html>
<html>
<head>
    <base href="../"/>
    <meta charset="UTF-8">
    <title>Basic DataGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="component/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="component/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="css/app.css">
    <script type="text/javascript" src="component/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="component/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="component/easyui/jquery.edatagrid.js"></script>
    <script type="text/javascript" src="component/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="js/config.js"></script>
</head>
<body class="easyui-layout" fit="true">
<table id="rule_code_env_datagrid" toolbar="#rule_code_env_datagrid_tb" >
    <thead>
    <tr>
        <th field="calculate_env_key" width="100" editor="{type:'validatebox',options:{required:true}}">变量码</th>
        <th field="calculate_env_name" width="100" editor="{type:'validatebox',options:{required:true}}">变量名</th>
        <th field="calculate_env_value" width="100" editor="{type:'validatebox',options:{required:true}}">默认值</th>
    </tr>
    </thead>
</table>
<div id="rule_code_env_datagrid_tb">
    <div  style="float: left">
        <a id="add_env_button" href="javascript:" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加变量</a>
        <a id="delete_env_button" href="javascript:" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除变量</a>
    </div>
    <div style="clear: both;"></div>
</div>
<script>
    $(document).ready(function () {
        var caculateId = $('#setting_rule_code_datagrid').datagrid('getSelected').id;
        $('#rule_code_env_datagrid').edatagrid({
            idField: 'id',
            method: 'get',
            url: baseUrl + '/caculateEnv/list.do?caculateId=' + caculateId,
            saveUrl: baseUrl + '/caculateenv/save.do?caculateId=' + caculateId,
            updateUrl: baseUrl + '/caculateenv/save.do?caculateId=' + caculateId,
            destroyUrl: baseUrl + '/caculateenv/delete.do?caculateId=' + caculateId,
            fit:true,
            singleSelect:true,
            fitColumns:true,
            onSuccess:function(index, row){
                $('#rule_code_env_datagrid').edatagrid('updateRow', {index: index, row: row});
            },
            onError: function (index, row) {
                $.messager.show({title: '数据不合法', msg:  JSON.parse(row.jqXHR.responseText).msg});
            }
        });
        $('#add_env_button').linkbutton({
            onClick: function () {
                var size = $($('#rule_code_env_datagrid').edatagrid('getRows')).size();
                $('#rule_code_env_datagrid').edatagrid('addRow', {index : size, row:{calculate_env_key:null, calculate_env_name: null, calculate_env_value: null}});
            }
        });
        $('#delete_env_button').linkbutton({
            onClick: function () {
                $('#rule_code_env_datagrid').edatagrid('destroyRow');
            }
        });
    });
</script>
</body>
</html>